package com.erpoa.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.HashMap;

/**
 * @author chenjimin
 * @Title: FactoryUtilMapper
 * @ProjectName oaerp
 * @Description: TODO
 * @date 2020/9/2116:43
 */
@Mapper
public interface FactoryUtilMapper {
    /**
     * @param hrno
     * @return
     */
    @Select("select genacti from ds2.gen_file where gen01=#{hrno}")
    String selectcheckUserValid(@Param("hrno") String hrno);

    @Select("select  nvl(sum(fQty),0) from MG_ProcessBarCode where fBarCode = #{barcode}")
    Integer getBarCodeTotalNum(String barcode);

    @Select(" select count(*) from MG_ProcessBarCode where fBarCode = #{barcode}")
    int checkBarcode(String barcode);

    @Select("select count(*) from mg_processbarcode m join ds2.tc_jjb_file t on m.fbarcode=#{barcode} " +
            "and t.tc_jjb001=#{jobnum} and m.ffactorycode=t.tc_jjb016 and m.fworkshopcode=t.tc_jjb017 ")
    int checkUserBelongApartment(@Param("barcode") String barcode, @Param("jobnum") String jobnum);

    @Select("select funfinQty,forderstatus from mg_orderplan where fid="
            + "(select distinct fplanid from mg_processbarcode where fbarcode= #{barcode} )")
    HashMap vaildsqlByBarcode(String barcode);

    @Select("select fplanqty,fpacknum from mg_orderplan where fid=(" +
            " select DISTINCT fplanid from mg_processbarcode where fbarcode= #{barcode})")
    HashMap selectplanpackByBarCode(String barcode);

    @Select("Select nvl(sum(fqty),0) from dsx5.mg_processbarcode" +
            " where fplanid=(Select distinct fplanid from dsx5.mg_processbarcode where fbarcode = #{barcode})" +
            " and fconfirm = 1 and (fdefective is null or fdefective <> 1)")
    int sumfqtyByBarCode(String barcode);

    @Select("Select nvl(sum(fqty),0) from dsx5.mg_processbarcode where fbarcode = #{barcode}")
    int sumfqty3ByBarCode(String barcode);

    @Select("select distinct forderno from MG_ProcessBarCode where fBarCode =#{barcode}")
    String isNormalOrderByBarCode(String barcode);

    @Select(" select count(sfa01) from ds2.sfa_file where sfa01=#{orderno}  and (sfa05-sfa06)<>0 ")
    int countsfa01ByorderNo(String orderno);
}
